package org.ar.gameserver.login.server;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.ar.gameserver.common.socket.PolicyServerSocket;
import org.ar.gameserver.common.util.LogUtils;
import org.ar.gameserver.common.util.PropertiesUtils;

public class PolicyServerHandler extends IoHandlerAdapter {
	@Override
	public void sessionClosed(IoSession session) throws Exception {
		super.sessionClosed(session);
	}

	public void messageReceived(IoSession session, Object message)
			throws Exception {
		try {
			String startPort = PropertiesUtils.getProperty("start.port");
			String endPort = PropertiesUtils.getProperty("end.port");
			String securityString = PolicyServerSocket.createSecurityString(startPort, endPort);
			session.write(securityString);
		} catch (Exception e) {
			LogUtils.error(e);
		}
	}

	public void exceptionCaught(IoSession session, Throwable cause)
			throws Exception {
		session.close(false);
	}
}